package com.camemax.rabbitmq.work_mode;

import com.camemax.rabbitmq.utils.PublisherModules;
import com.camemax.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

// *********************
// ** @Date: 2021-06-09
// ** @Author: Camemax
// ** @Description: Publisher in work mode.
// *********************
public class WorkMode_Publisher {
    private static final String EXCHANGE_NAME = "";
    private static final String ROUTING_KEY = "work-queue";
    public static void main(String[] args) {
        ConnectionFactory factory = RabbitMQUtils.createFactory();
        Connection connection = null;
        Channel channel = null;

        try {
            connection = factory.newConnection();
            channel = connection.createChannel();

            // for循环分发消息=> { Exchange: ""(默认交换机), RoutingKey: "work-queue"}
            for ( int i = 0 ; i < 20 ; i ++){
                channel.basicPublish(
                        EXCHANGE_NAME,
                        ROUTING_KEY, // 默认交换机下，RoutingKey为队列名
                        null,
                        ("message"+i ).getBytes()
                );
            }

            System.out.println("Publisher sends finished!");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            RabbitMQUtils.close(channel, connection);
        }
    }
}
